package com.bay1ts.service.impl;

import com.bay1ts.dao.*;
import com.bay1ts.domain.*;
import com.bay1ts.service.GoverService;
import com.bay1ts.service.RequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenuu on 2016/4/2.
 */
@Service("goverService")
public class GoverServiceImpl implements GoverService {
    @Autowired
    private RequestService requestService;
    @Autowired
    private SubjectContestMapper subjectContestMapper;
    @Autowired
    private VocationaQualificationMapper vocationaQualificationMapper;
    @Autowired
    private EntrepreneurshipMapper entrepreneurshipMapper;
    @Autowired
    private RequestMapper requestMapper;
    @Autowired
    private UsersMapper usersMapper;
    //获取系级老师通过的结果 参数1表示通过的，0表示未通过的
    public List<Request> getResult(int isPassed) {
        List<Request> list=new ArrayList<Request>();
        if(isPassed==1){
            list=requestMapper.selectAllPassed();
        }else {
            list=requestMapper.selectAllApply();
        }
        return list;
    }

    public void addCredit(Long requestId) {
        Request request=requestMapper.selectByPrimaryKey(requestId);
        //下面要有逻辑 表示把请求的学分加上了。
        int score=0;//应该是request
        if (request.getSubId()!=null){
            SubjectContest subjectContest=subjectContestMapper.selectByPrimaryKey(request.getSubId());
            score=subjectContest.getAppliedSocre();
            //下面获取申请的学分
        }else if(request.getVocId()!=null) {
            VocationaQualification vocationaQualification=vocationaQualificationMapper.selectByPrimaryKey(request.getVocId());
            score=vocationaQualification.getAppliedScore();
        }else{
            Entrepreneurship entrepreneurship=entrepreneurshipMapper.selectByPrimaryKey(request.getVocId());
            score=entrepreneurship.getAppliedScore();
        }
        Long stuId=request.getStuId();
        Users users=usersMapper.selectByPrimaryKey(stuId);
        //下面应该是设置增加分数的代码
        //stu_id是学号
        int myScore=users.getScore();
        myScore+=score;
        users.setScore(myScore);
        usersMapper.updateByPrimaryKey(users);
    }

}
